/**********************************************************************************
**
** Copyright (C) 2009 Jostein Bratlie
** Contact: jostein.bratlie@gmail.com | http://bratlie.info | http://episteme.hin.no
**
** This file is part of GMQtExt, a GMlib and Qt extension library
**
** GMQtExt is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** GMQtExt is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with GMQtExt.  If not, see <http://www.gnu.org/licenses/>.
**
**********************************************************************************/

#ifndef EDITORFACTORY_H
#define EDITORFACTORY_H


// Qt
#include <QDialog>

// Qt Solutions
#include "qteditorfactory.h"

// local
#include "propertymanager.h"

class QLabel;
class QSpinBox;

namespace GMQtExt {



  class SurfacePlotDialog : public QDialog {
  public:
    SurfacePlotDialog( QWidget* parent = 0x0 );

    void get( GMlib::Point<int,2>& no_samp, GMlib::Point<int,2>& no_der );
    void set( const GMlib::Point<int,2>& no_samp, const GMlib::Point<int,2>& no_der );

  private:
    QSpinBox      *_samp_u;
    QSpinBox      *_samp_v;
    QSpinBox      *_der_u;
    QSpinBox      *_der_v;

  }; // END class SurfacePlotDialog



  class SurfacePlotEditWidget : public QWidget {
    Q_OBJECT
  public:
    SurfacePlotEditWidget( QWidget* parent = 0x0 );

  private:
    GMlib::Point<int,2>   _no_samp;
    GMlib::Point<int,2>   _no_der;

    QLabel                *_label;

  public slots:
    void                  setNoDerivatives( const GMlib::Point<int,2>& no_der );
    void                  setNoSamples( const GMlib::Point<int,2>& no_der );
    void                  setValue( const GMlib::Point<int,2>& no_samp, const GMlib::Point<int,2>& no_der );

  private slots:
    void                  _slotButtonClicked();
    void                  _slotReplotButtonClicked();

  signals:
    void                  signForcedReplot();
    void                  signValueChanged( const GMlib::Point<int,2>&, const GMlib::Point<int,2>& );

  }; // END class SurfacePlotEditWidget



  class SurfacePlotEditorFactory : public QtAbstractEditorFactory< SurfacePlotPropertyManager > {
    Q_OBJECT
  public:
    SurfacePlotEditorFactory( QObject* parent = 0x0 );
    ~SurfacePlotEditorFactory();

  protected:
    void            connectPropertyManager( SurfacePlotPropertyManager* manager );
    QWidget*        createEditor( SurfacePlotPropertyManager* manager, QtProperty* property, QWidget* parent );
    void            disconnectPropertyManager( SurfacePlotPropertyManager* manager );

  private:
    QMap<QtProperty*, QList<SurfacePlotEditWidget*> >   _editors;
    QMap<SurfacePlotEditWidget*, QtProperty*>           _editor_to_property;

  private slots:
    void            _slotEditorDestroyed( QObject* object );
    void            _slotForcedReplot();
    void            _slotSetValue( const GMlib::Point<int,2>&, const GMlib::Point<int,2>& );
    void            _slotValueChanged( QtProperty*, const GMlib::Point<int,2>&, const GMlib::Point<int,2>& );

  signals:
    void            signForcedReplot();

  }; // END class SurfacePlotEditorFactory



} // END namespace GMQtExt




#endif // EDITORFACTORY_H
